﻿@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_PageLayout.cshtml";
} 
@section HeadSection
{
    <script type="text/javascript">
        var url = "";
        $(function() {
            $('#RechargeList').datagrid({
                title: '充值记录管理',
                iconCls: 'icon-edit',
                url: '/Recharge/RechargeList',
                striped: true,
                idField: 'RCID',
                border: true,
                loadMsg: '数据加载中...',
                singleSelect: true,
                pagination: true,
                pageSize: 20,
                pageList: [15, 20, 25, 30],
                frozenColumns: [[{ field: 'ck', checkbox: true }]],
                columns: [
                    [
                        { field: 'UserTitle', title: '充值商户', width: 130 },
                        { field: 'UserOrderNo', title: '订单号', width: 150, align: 'center' },
                        {
                            field: 'RCType',
                            title: '充值类型',
                            width: 70,
                            align: 'center',
                            formatter: function(val, rec) {
                                if (val == 1) {
                                    return "<font style='color:green;'>手机话费</font>";
                                } else if (val == 2) {
                                    return "<font style='color:red;'>QQ币</font>";
                                } else if (val == 3) {
                                    return "<span style='color:blue'>礼品卡</span>";
                                } else if (val == 4) {
                                    return "<span style='color:orangered'>流量包</span>";
                                }
                                else if (val == 5) {
                                    return "<span style='color:darkred'>微信红包</span>";
                                }
                            }
                        },
                        { field: 'RCTarget', title: '手机/QQ号/卡编号', width: 90, align: 'center' },
                        { field: 'OrderAmount', title: '充值数量', width: 60, align: 'center' },
                        {
                            field: 'RechargeStatus',
                            title: '充值状态',
                            width: 60,
                            align: 'center',
                            formatter: function(val, rec) {
                                if (val == "1") {
                                    return "<font style='color:green;'>成功</font>";
                                } else {
                                    return "<font style='color:red;'>未成功</font>";
                                }
                            }
                        },
                        {
                            field: 'OrderTime',
                            title: '下单时间',
                            width: 130,
                            formatter: function(val, rec) {
                                return JSONDateToJSDate(val);
                            }
                        },
                        {
                            field: 'RechargeSuccessTime',
                            title: '充值结果时间',
                            width: 130,
                            formatter: function(val, rec) {
                                if (val) {
                                    return JSONDateToJSDate(val);
                                } else {
                                    return "";
                                }
                            }
                        },
                        { field: 'RechargeErrorReason', title: '失败原因', align: 'center', width: 180 }
                        //由于和业务平台已开发补充功能，此功能暂不启用
                        ,
                        {
                            field: 'opt',
                            title: '失败补充',
                            align: 'center',
                            width: 70,
                            formatter: function(val, rec) {
                                if (rec.RechargeStatus == 0 || rec.RechargeStatus == 3) {
                                    return '<a href="javascript:void(0);" onclick="if(confirm(\'确认补充吗？\')) { Recharge(' + rec.RCID + ');}" style="color:orangered;">补充</a>';
                                }
                            }
                        }
                    ]
                ],
                toolbar: []
            });


            //尺寸
            $('#RechargeList').datagrid('resize');

            //加载搜索框//在这个样式下。加载搜索框的div
            $(".datagrid-toolbar").append($("#divsearch"));
        });

        //搜索
        function doSearch() {
            $('#RechargeList').datagrid('load', { userId: $("#selReUser").combobox("getValue"), orderNo: $("#orderNo").val(), rcTarget: $("#rcTarget").val(), rcStatus: $("#selRechargeStatus").combobox("getValue"), beginTime: $("#beginTime").datetimebox("getValue"), endTime: $("#endTime").datetimebox("getValue") });
        }

        //补发充值
        function Recharge(rcId) {
            $.post("RechargeAgain", { rcId: rcId }, function(data) {
                alert(data.msg);
                $('#RechargeList').datagrid('reload');

            }, "json");
        }

        function Export() {
            var userId = $("#selReUser").combobox("getValue");
            var orderNo = $("#orderNo").val();
            var rcTarget = $("#rcTarget").val();
            var rcStatus = $("#selRechargeStatus").combobox("getValue");
            var beginTime = $("#beginTime").datetimebox("getValue");
            var endTime = $("#endTime").datetimebox("getValue");

            var form = $("<form>");
            form.attr('style', 'display:none');
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', 'Export');

            var input1 = $('<input>');
            input1.attr('type', 'hidden');
            input1.attr('name', 'rcStatus');
            input1.attr('value', rcStatus);

            var input2 = $('<input>');
            input2.attr('type', 'hidden');
            input2.attr('name', 'userId');
            input2.attr('value', userId);

            var input3 = $('<input>');
            input3.attr('type', 'hidden');
            input3.attr('name', 'orderNo');
            input3.attr('value', orderNo);

            var input4 = $('<input>');
            input4.attr('type', 'hidden');
            input4.attr('name', 'rcTarget');
            input4.attr('value', rcTarget);

            var inputBeginTime = $('<input>');
            inputBeginTime.attr('type', 'hidden');
            inputBeginTime.attr('name', 'beginTime');
            inputBeginTime.attr('value', beginTime);

            var inputEndTime = $('<input>');
            inputEndTime.attr('type', 'hidden');
            inputEndTime.attr('name', 'endTime');
            inputEndTime.attr('value', endTime);

            $('body').append(form);
            form.append(input1);
            form.append(input2);
            form.append(input3);
            form.append(input4);
            form.append(inputBeginTime);
            form.append(inputEndTime);
            form.submit();
            form.remove();
        }
    </script>
}
<div id="divsearch" style="padding:5px;height:auto;">
    <div>
    充值项目：<select id="selReUser" class="easyui-combobox" style="width: 180px" >
    <option value="0">请选择</option>
    @foreach(Beway.ValueAdded.Model.ReUser ru in ViewBag.ReUserList)
    {
        <option value="@ru.UserID">@ru.UserTitle</option>
    }
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    充值结果：<select id="selRechargeStatus" class="easyui-combobox">
        <option value="-1">所有</option>
        <option value="1">成功</option>
        <option value="0">失败</option>
    </select>
    订单号：<input type="text" name="orderNo" id="orderNo" style="width: 150px" />&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <div style="margin-top:10px">
    充值手机/QQ号：<input type="text" name="rcTarget" id="rcTarget" style="width: 100px" />&nbsp;&nbsp;&nbsp;&nbsp;
    下单时间：
    <input class="easyui-datetimebox" id="beginTime" style="width:150px" /> - <input class="easyui-datetimebox" id="endTime" style="width: 150px" />
    <a href="#" class="easyui-linkbutton" onclick="doSearch();" iconcls="icon-search">搜索</a>
     <a href="#" class="easyui-linkbutton" onclick="Export();" iconcls="icon-redo">导出</a>
    </div>
</div>
<table id="RechargeList" toolbar="#divsearch">
</table> 
